package com.sxj.corejava.code08_常用类.日期类;

import java.util.Date;

/**
 * @author 石小俊
 */
public class Test02_常用方法 {

    public static void main(String[] args) {
        Date date = new Date();
        System.out.println(date);
        // 获取当前毫秒数
        long time = date.getTime();
        System.out.println(time);
        long current = System.currentTimeMillis();
        System.out.println(current);
        long yesterday = current - 24 * 60 * 60 * 1000;
        // 设置毫秒数
//        date.setTime(yesterday);
        System.out.println(date);

        // 过时方法
        System.out.println(date.getYear() + 1900);
        System.out.println(date.getMonth() + 1);
        System.out.println(date.getDate());
        System.out.println(date.getDay());
        System.out.println((date.getYear() + 1900) + "年" + (date.getMonth() + 1) + "月" + date.getDate() + "日 " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds());

        Date date2 = new Date(yesterday);
        System.out.println(date);
        System.out.println(date2);
        System.out.println("判断date是否在date2的日期之前:" + date.before(date2));
        System.out.println("判断date是否在date2的日期之后:" + date.after(date2));
        // 1:大于 0:等于 -1:小于
        System.out.println("date是否比date2大:" + date.compareTo(date2));
        System.out.println("date2是否比date大:" + date2.compareTo(date));
    }

}
